{% extends "base.html" %}
{% if board.bo_use_sideview %}
    {% import "/sideview/macros.html" as sideview %}
{% endif %}

{% block head %}
    <script src="/static/js/viewimageresize.js"></script>
{% endblock head %}

{% block title %}{{ write.wr_subject|truncate(20, False, '...', 0) }} > {{ board.subject }}{% endblock title %}
{% block subtitle %}{{ board.subject }}{% endblock subtitle %}

{% block content %}
{% set board_config=board_config(request, board) %}
{% set login_member=request.state.login_member %}
{% set is_admin=get_admin_type(request, login_member.mb_id, board=board) %}
{% set bo_table_width=board.bo_table_width if board.bo_table_width > 0 else 100 %}
    <!-- 开始阅读帖子 { -->
      <div id="loading" class="loading position-fixed top-0 start-0 w-100 h-100 bg-black bg-opacity-50" style="z-index: 1000;"><i class="fa-solid fa-spinner position-absolute top-50 start-50 translate-middle text-white" style="font-size: 5rem;"></i></div>
      <div class="post-swiper">
        <div class="swiper-wrapper">
          <div class="swiper-slide"></div>
          <div id="bo_v" class="swiper-slide mb-4" style="width:{{ bo_table_width }}{% if bo_table_width <= 100 %}%{% else %}px{% endif %};box-sizing:border-box">
            <header>
                <h2 id="bo_v_title" class="m-0 p-0">
                    {% if board.bo_use_category and write.ca_name %}
                        <span class="bo_v_cate d-inline-block main-font px-3 rounded-2" style="line-height: 20px;">{{ write.ca_name }}</span>
                    {% endif %}
                    <span class="bo_v_tit d-block fs-1 mt-5 mb-4 main-font fw-bold" style="word-break: break-all;">{{ write.wr_subject|truncate(250, False, '...', 0) }}</span>
                </h2>
            </header>
    
            <section id="bo_v_info" class="d-flex justify-content-between align-items-center main-bb mt-5 pb-5 sub-font">
                <h2 class="blind">页面信息</h2>
                <div class="profile_info d-inline-flex">
                    <div class="me-3 rounded-circle overflow-hidden" style="width: 50px;height: 50px;"><img src="{{ get_member_image(write.mb_id) }}" style="width: 100%;" alt="profile_image"></div>
                    <div class="profile_info_ct py-2 fs-5" style="line-height: 18px;">
                        <span class="blind">按作者</span>
                        <strong class="d-inline-block me-3 fw-normal" style="color: #888;">
                            {% if board.bo_use_sideview %}
                                {{ sideview.get(request, write.mb_id, write.name, write.wr_email, write.wr_homepage)|safe }}
                            {% else %}
                                <span class="{% if write.mb_id %}member{% else %}guest{% endif %}">
                                    {{ write.name }}
                                </span>
                            {% endif %}
                            {% if write.ip %}
                            &nbsp;({{ write.ip }})
                            {% endif %}
                        </strong>
                        <br>
                        <span class="blind">评论</span><strong class="d-inline-block me-3 fw-normal"><a href="#bo_vc" style="color:#888;"> <i class="fa fa-regular fa-commenting" aria-hidden="true"></i> {{ write.wr_comment|number_format }}枪</a></strong>
                        <span class="blind">询价</span><strong class="d-inline-block me-3 fw-normal" style="color:#888;"><i class="fa fa-eye" aria-hidden="true"></i> {{ write.wr_hit|number_format }}sashy</strong>
                        <strong class="if_date d-inline-block fw-normal"><span class="blind">写作日</span><i class="fa fa-regular fa-clock" aria-hidden="true"></i> {{ write.wr_datetime }}</strong>
                    </div>
                </div>
                <!-- 启动帖子的顶部按钮 { -->
                <div id="bo_v_top" >
                    <ul class="d-inline-flex p-0 list-unstyled break-word">
                        <li>
                            <a href="{{ url_for('list_post', bo_table=board.bo_table)|set_query_params(request) }}" class="btn_b01 btn" title="列表">
                                <i class="fa fa-list" aria-hidden="true"></i><span class="blind">列表</span>
                            </a>
                        </li>
                        {% if is_reply %}
                        <li>
                            <a href="{{ url_for('write_form_add', bo_table=board.bo_table)|set_query_params(request, parent_id=write.wr_id) }}" class="btn_b01 btn" title="答案">
                                <i class="fa fa-reply" aria-hidden="true"></i><span class="blind">答案</span>
                            </a>
                        </li>
                        {% endif %}
                        {% if is_write %}
                        <li>
                            <a href="{{ url_for('write_form_add', bo_table=board.bo_table)|set_query_params(request) }}" class="btn_b01 btn" title="写作">
                                <i class="fa fa-pencil" aria-hidden="true"></i><span class="blind">写作</span>
                            </a>
                        </li>
                        {% endif %}
                        {% if is_admin or write.mb_id == login_member.mb_id or not write.mb_id %}
                        <li class="position-relative">
                            <a class="btn_b01 btn btn_more_opt is_view_btn px-4">
                                <i class="fa fa-ellipsis-v" aria-hidden="true"></i><span class="blind">公告板列表选项</span>
                            </a>
                            <ul class="more_opt is_view_btn position-absolute end-0 p-0" style="display: none;">
                                <li>
                                    <a href="{{ url_for('write_form_edit', bo_table=board.bo_table, wr_id=write.wr_id)|set_query_params(request) }}">
                                        校正<i class="fa fa-pen-to-square" aria-hidden="true"></i>
                                    </a>
                                </li>
                                <li>
                                    <a href="{{ url_for('delete_post', bo_table=board.bo_table, wr_id=write.wr_id)|set_query_params(request) }}" onclick="del(this.href); return false;">
                                        删除<i class="fa fa-regular fa-trash-can" aria-hidden="true"></i>
                                    </a>
                                </li>
                                {% if is_admin %}
                                <li>
                                    <a href="#" onclick="board_move(this.href, 'copy'); return false;">
                                        复制<i class="fa fa-regular fa-file" aria-hidden="true"></i>
                                    </a>
                                </li>
                                <li>
                                    <a href="#" onclick="board_move(this.href, 'move'); return false;">
                                        移动<i class="fa fa-arrows" aria-hidden="true"></i>
                                    </a>
                                </li>
                                {% endif %}
                            </ul> 
                        </li>
                        {% endif %}
                    </ul>
                    <script>
                        jQuery(function($){
                            // 公告板视图按钮选项
                            $(".btn_more_opt.is_view_btn").on("click", function(e) {
                                e.stopPropagation();
                                $(".more_opt.is_view_btn").toggle();
                            })
                            $(document).on("click", function (e) {
                                if(!$(e.target).closest('.is_view_btn').length) {
                                    $(".more_opt.is_view_btn").hide();
                                }
                            });
                        });
                    </script>
                </div>
                <!-- } 帖子顶部按钮的结尾 -->
            </section>
    
            <div id="bo_v_atc">
                <h2 class="blind">文本</h2>
                  <div id="bo_v_share" class="position-relative py-4">
                    <!-- SNS START -->
                    <!-- SNS END -->
                    {% if login_member %}
                        <a href="{{ url_for('scrap_form', bo_table=board.bo_table, wr_id=write.wr_id) }}" target="_blank" class="btn btn_b03" onclick="win_scrap(this.href); return false;">
                            <i class="fa fa-bookmark" aria-hidden="true"></i>废料
                        </a>
                    {% endif %}
                  </div>
    
                <!-- 文件输出 START -->
                <div id="bo_v_img" class="w-100 overflow-hidden">
                    {% for image in images %}
                        <img src="/{{ image.bf_file }}" width="{{ board_config.image_width }}" alt="" title="">
                    {% endfor %}
    
                </div>
                <!-- 文件输出 END -->
    
                <!-- 开始文本内容 { -->
                <div id="bo_v_con" class="{{ request.state.editor }} main-font">
                    {{ write.wr_content|set_image_width(board_config.image_width)|url_auto_link(request)|safe }}
                </div>
                <!-- } 文本内容结尾 -->
                <!-- 签名 START -->
                {{ board_config.get_member_signature(write.mb_id) }}
                <!-- 签名 END -->
    
                <!--  开始推荐的雨 { -->
                <div id="bo_v_act">
                    {% if board.bo_use_good %}
                    <span class="bo_v_act_gng">
                        <a href="/bbs/ajax/good/{{ board.bo_table }}/{{ write.wr_id }}/good" id="good_button" class="bo_v_good {{ "active" if write.is_good else "" }}">
                            <i class="fa fa-regular fa-thumbs-up" aria-hidden="true"></i>
                            <span class="blind">待定</span>
                            <strong>{{ write.wr_good }}</strong>
                        </a>
                        <b id="bo_v_act_good"></b>
                    </span>
                    {% endif %}
                    {% if board.bo_use_nogood %}
                    <span class="bo_v_act_gng">
                        <a href="/bbs/ajax/good/{{ board.bo_table }}/{{ write.wr_id }}/nogood" id="nogood_button" class="bo_v_nogood {{ "active" if write.is_nogood else "" }}">
                            <i class="fa fa-regular fa-thumbs-down" aria-hidden="true"></i>
                            <span class="blind">非推荐</span>
                            <strong>{{ write.wr_nogood }}</strong>
                        </a>
                        <b id="bo_v_act_nogood"></b>
                    </span>
                    {% endif %}
                </div>
                <!-- }  完成建议的雨水 -->
            </div>
    
            <section id="bo_v_file">
                <h2 class="blind">附件</h2>
                <ul class="m-0 list-unstyled">
                {% for file in files %}
                    <li class="position-relative d-flex align-items-center file-border rounded-3 transition-effect p-4 mt-3" style="color: #b2b2b2;">
                        <i class="fa fa-folder-open fs-1 me-4" aria-hidden="true"></i>
                        <div>
                          <a href="/board/{{ board.bo_table }}/{{ write.wr_id }}/download/{{ file.bf_no }}" class="d-block text-decoration-none break-word main-font fs-5">
                            <strong>{{ file.bf_source }}</strong>  ({{ file.bf_filesize|filesizeformat }})
                          </a>
                          <span class="fs-5">{{ file.bf_download }}下载剧集 | DATE : {{ file.bf_datetime }}</span>
                        </div>
                    </li>
                {% endfor %}
                </ul>
            </section>
    
        
        <!-- 启动相关链接 { -->
        {% if links %}
        <section id="bo_v_link">
            <h2 class="blind">相关链接</h2>
            <ul class="m-0 list-unstyled">
                {% for link in links %}
                <li class="position-relative d-flex align-items-center file-border rounded-3 transition-effect p-4 mt-3" style="color: #b2b2b2;">
                    <i class="fa fa-link fs-1 me-4" aria-hidden="true"></i>
                    <div>
                      <a href="{{ url_for("link_url", bo_table=board.bo_table, wr_id=write.wr_id, no=link.no) }}" class="d-block text-decoration-none break-word main-font fs-5" target="_blank">
                        <strong>{{ link.url|truncate(70, False, '...', 0) }}</strong>
                      </a>
                      <span class="fs-5">{{ link.hit|number_format }}会议连接</span>
                    </div>
                </li>
                {% endfor %}
            </ul>
        </section>
        {% endif %}
        <!-- } 相关链接结束 -->
    
        <ul id="bo_v_nb" class="position-relative row mt-3 mb-5 p-0">
            {% if prev %}
            <li class="me-auto col-md-6 mb-3 mb-md-0">
              <a href="{{ url_for('read_post', bo_table=board.bo_table, wr_id=prev.wr_id )|set_query_params(request) }}" class="btn_prv rounded-3 text-decoration-none sub-font">
                <i class="fa fa-chevron-up" aria-hidden="true"></i>
                <div class="fs-5" style="width: calc(100% - 40px);">
                  <p class="mb-0">上一篇文章</p>
                  <p class="fs-3 fw-bold text-truncate py-2 mb-0">{{ prev.wr_subject }}</p>
                  <p class="mb-0">{{ prev.wr_datetime }}</p>
                </div>
              </a>
            </li>
            {% endif %}
            {% if next %}
            <li class="ms-auto col-md-6">
              <a href="{{ url_for('read_post', bo_table=board.bo_table, wr_id=next.wr_id )|set_query_params(request) }}" class="btn_next rounded-3 text-decoration-none text-light">
                <div class="fs-5" style="width: calc(100% - 40px);">
                  <p class="mb-0">下一篇文章</p>
                  <p class="fs-3 fw-bold text-truncate py-2 mb-0">{{ next.wr_subject }}</p>
                  <p class="mb-0">{{ next.wr_datetime }}</p>
                </div>
                <i class="fa fa-chevron-down" aria-hidden="true"></i> 
              </a>
            </li>
            {% endif %}
        </ul>
    
        <script>
            // 有限的字符数
            var char_min = parseInt({{ board.bo_comment_min }}); // 最小值
            var char_max = parseInt({{ board.bo_comment_max }}); // 最大值
        </script>
        <button type="button" id="cmt_btn" class="d-flex justify-content-between align-items-center w-100 text-start border-0 fw-bold bg-transparent outline-none fs-4 mt-5 pb-4">
            <span class="me-2 em-font"><b class="fs-4 main-font me-1">评论</b>{{ comments|count|number_format }}</span>
            <span class="cmt_more"><i class="fa fa-chevron-down" aria-hidden="true"></i></span>
        </button>
        <!-- 开始评论 { -->
        <section id="bo_vc">
            <h2 class="blind">评论列表</h2>
            {% for comment in comments %}
            {% set reply_depth=comment.wr_comment_reply|length %}
            <article id="c_{{ comment.wr_id }}" class="position-relative d-flex justify-content-between my-4 main-bb" {% if reply_depth %}style="margin-left:{{ reply_depth * 50 }}px;border-top-color:#e0e0e0"{% endif %}>
              <div class="d-flex w-100 main-font">
                <div class="me-3 rounded-circle overflow-hidden" style="width: 50px;height: 50px;"><img src="{{ get_member_image(write.mb_id) }}" alt="profile_image" style="width: 100%;"></div>
                <div class="fs-5" style="width: calc(100% - 50px);">
                    <header class="position-relative main-font">
                        <h2 class="blind">{{ comment.name }}来自你的评论</h2>
                        {% if board.bo_use_sideview %}
                            {{ sideview.get(request, comment.mb_id, comment.name, comment.wr_email, comment.wr_homepage)|safe }}
                        {% else %}
                            <span class="{% if comment.mb_id %}member{% else %}guest{% endif %}">
                                {{ comment.name }}
                            </span>
                        {% endif %}
                        {% if comment.ip %}
                            <span class="blind">iPi</span>
                            <span class="blind">iPi</span>
                            <span>({{ comment.ip }})</span>
                        {% endif %}
                        <span class="blind">写作日</span>
                        <span style="color: #888;">
                            <i class="fa fa-regular fa-clock" aria-hidden="true"></i>
                            <time datetime="{{ comment.wr_datetime|datetime_format }}">{{ comment.wr_datetime|datetime_format }}</time>
                        </span>
                    </header>
            
                    <div class="lh-base pt-3 pb-4 main-font">
                        <p>
                            {% if comment.is_secret %}
                                <img src="{{ url_for('static', path="/img/icon_secret.gif") }}" alt="秘密评论">
                            {% endif %}
                            {% if comment.is_secret_content %}
                                <a href="{{ url_for('password_page', action="comment-view", bo_table=board.bo_table, wr_id=comment.wr_id) }}" class="s_cmt">
                                    检查注释
                                </a>
                            {% else %}
                                {{ comment.wr_content|safe }}
                            {% endif %}
                        </p>
                    </div>
                    <span id="edit_{{ comment.wr_id }}" class="bo_vc_w"></span><!-- 校正 -->
                    <span id="reply_{{ comment.wr_id }}" class="bo_vc_w"></span><!-- 答案 -->
    
                    <input type="hidden" value="{% if "secret" in comment.wr_option %}secret{% endif %}" id="secret_comment_{{ comment.wr_id }}">
                    <textarea id="save_comment_{{ comment.wr_id }}" style="display:none">{{ comment.save_content|safe }}</textarea>
                </div>
              </div>
                <div class="bo_vl_opt">
                    <button type="button" class="btn_cm_opt btn_b01 btn fs-4" style="color: #bababa;">
                        <i class="fa fa-ellipsis-v" aria-hidden="true"></i>
                        <span class="blind">注释选项</span>
                    </button>
                    <ul class="bo_vc_act" style="display: none;">
                        {% if comment.is_reply %}
                        <li><a href="javascript:;" onclick="comment_box('{{ comment.wr_id }}', 'c'); return false;">答案</a></li>
                        {% endif %}
                        {% if comment.is_edit %}
                        <li><a href="javascript:;" onclick="comment_box('{{ comment.wr_id }}', 'cu'); return false;">校正</a></li>
                        {% endif %}
                        {% if comment.is_del %}
                        <li><a href="/board/delete_comment/{{ board.bo_table }}/{{ comment.wr_id }}" onclick="comment_delete(this.href); return false;">删除</a></li>
                        {% endif %}
                    </ul>
                </div>
                <script>
                $(function() {
                    // 打开 “注释选项” 窗口
                    $(".btn_cm_opt").on("click", function(){
                        $(this).parent("div").children(".bo_vc_act").show();
                    });
                        
                    // 关闭 “注释选项” 窗口
                    $(document).mouseup(function (e){
                        var container = $(".bo_vc_act");
                        if( container.has(e.target).length === 0)
                        container.hide();
                    });

                    // 编辑评论, 取消答案
                    $("#btn_cancel").click(function() {
                        comment_box('', 'c');
                    });
                });
                </script>
            </article>
            {% else %}
            <p id="bo_vc_empty" class="sub-font fs-5 m-0 text-center" style="padding: 80px 0; color: #777;">无注册评论.</p>
            {% endfor %}
        </section>
        <!-- } 评论结束 -->
    
        {% if is_comment_write %}
            <!-- 开始写评论 { -->
            <aside id="bo_vc_w" class="bo_vc_w">
                <h2>写评论</h2>
                <form name="fviewcomment" id="fviewcomment" method="post" autocomplete="off"
                    action="{{ url_for('write_comment_update', bo_table=board.bo_table)|set_query_params(request) }}" 
                    onsubmit="return fviewcomment_submit(this);">
                    <input type="hidden" name="w" id="w" value="c">
                    <input type="hidden" name="bo_table" value="{{ board.bo_table }}">
                    <input type="hidden" name="wr_id" value="{{ write.wr_id }}">
                    <input type="hidden" name="comment_id" value="{{ request.query_params.c_id }}" id="comment_id">
                    <input type="hidden" name="sca" value="{{ request.query_params.sca }}">
                    <input type="hidden" name="sfl" value="{{ request.query_params.sfl }}">
                    <input type="hidden" name="stx" value="{{ request.query_params.stx }}">
                    <input type="hidden" name="spt" value="{{ request.query_params.spt }}">
                    <input type="hidden" name="page" value="{{ request.query_params.page }}">
                    <input type="hidden" name="token" value="">
                    
                    {% if board.bo_comment_min and board.bo_comment_max %}
                    <script> check_byte('wr_content', 'char_count'); </script>
                    <strong id="char_cnt"><span id="char_count">0</span>字母</strong>
                    {% endif %}
    
                    <span class="blind">内容</span>
                    <textarea id="wr_content" name="wr_content" maxlength="10000" required="" class="required"
                        {% if board.bo_comment_min and board.bo_comment_max %}
                            onkeyup="check_byte('wr_content', 'char_count');"
                        {% endif %}
                        title="评论内容" placeholder="请输入您的评论"></textarea>
    
                    <script>
                    $(document).on("keyup change", "textarea#wr_content[maxlength]", function() {
                        var str = $(this).val()
                        var mx = parseInt($(this).attr("maxlength"))
                        if (str.length > mx) {
                            $(this).val(str.substr(0, mx));
                            return false;
                        }
                    });
                    </script>
                    <div class="bo_vc_w_wr">
                        <div class="bo_vc_w_info">
                            {% if not request.state.login_member %}
                                <label for="wr_name" class="blind">姓名<strong> 必不可少的</strong></label>
                                <input type="text" name="wr_name" value="" id="wr_name" required class="frm_input required" size="25" placeholder="姓名">
                                <label for="wr_password" class="blind">密码<strong> 必不可少的</strong></label>
                                <input type="password" name="wr_password" id="wr_password" required class="frm_input required" size="25"  placeholder="密码">
                                <!-- Captcha Start -->
                                <fieldset id="captcha" class="captcha">{% include captcha_widget(request) ignore missing %}</fieldset>
                                <!-- Captcha End -->
                            {% endif %}
                            
    
                            <span class="bo_vc_secret chk_box">
                                <input type="checkbox" name="wr_secret" value="secret" id="wr_secret" class="selec_chk">
                                <label for="wr_secret" class="icon_lock">
                                    <span>&nbsp;</span>秘密评论
                                </label>
                            </span>
                        </div>
                        <div class="btn_confirm text-end">
                            <button type="button" id="btn_cancel" class="btn_cancel btn">取消</button>
                            <button type="submit" id="btn_submit" class="btn_submit">注册评论</button>
                        </div>
                    </div>
                </form>
            </aside>
    
            <script>
            var save_before = '';
            var save_html = document.getElementById('bo_vc_w').innerHTML;

            function fviewcomment_submit(f)
            {
                // 为了摆脱这两个空间
                var pattern = /(^\s*)|(\s*$)/g; // \s 空格字符
                document.getElementById('wr_content').value = document.getElementById('wr_content').value.replace(pattern, "");
                if (char_min > 0 || char_max > 0)
                {
                    check_byte('wr_content', 'char_count');
                    var cnt = parseInt(document.getElementById('char_count').innerHTML);
                    if (char_min > 0 && char_min > cnt) {
                        alert("评论是 "+char_min+"你需要写更多的信。.");
                        return false;
                    } else if (char_max > 0 && char_max < cnt) {
                        alert("评论是 "+char_max+"你需要写的比字母少。.");
                        return false;
                    }
                }
                else if (!document.getElementById('wr_content').value)
                {
                    alert("请输入评论.");
                    return false;
                }
    
                if (typeof(f.wr_name) != 'undefined')
                {
                    f.wr_name.value = f.wr_name.value.replace(pattern, "");
                    if (f.wr_name.value == '')
                    {
                        alert('未输入姓名.');
                        f.wr_name.focus();
                        return false;
                    }
                }
    
                if (typeof(f.wr_password) != 'undefined')
                {
                    f.wr_password.value = f.wr_password.value.replace(pattern, "");
                    if (f.wr_password.value == '')
                    {
                        alert('未输入密码.');
                        f.wr_password.focus();
                        return false;
                    }
                }
    
                f.token.value = generate_token();
                if (f.token.value == "") {
                    alert("创建令牌失败.");
                    return false;
                }
    
                // captcha 使用时
                if (typeof check_captcha === "function") {
                    if (!check_captcha(f)) {
                        return false;
                    }
                }
                
                document.getElementById("btn_submit").disabled = true;
    
                return true;
            }
    
            function comment_box(comment_id, work)
            {
                var el_id,
                    form_el = 'fviewcomment',
                    respond = document.getElementById(form_el);
    
                // 当评论名称出现时回答, 校正
                if (comment_id) {
                    if (work == 'c') {
                        el_id = 'reply_' + comment_id;
                    } else {
                        el_id = 'edit_' + comment_id;
                    }
                    // 校正, 回答时, 请参阅 “取消” 按钮
                    document.getElementById('btn_cancel').style.display = '';
                } else {
                    el_id = 'bo_vc_w';
                    document.getElementById('btn_cancel').style.display = 'none';
                }
    
                if (save_before != el_id)
                {
                    if (save_before)
                    {
                        document.getElementById(save_before).style.display = 'none';
                    }
    
                    document.getElementById(el_id).style.display = '';
                    document.getElementById(el_id).appendChild(respond);
                    //输入值初始化
                    document.getElementById('wr_content').value = '';
                    
                    // 编辑评论
                    if (work == 'cu')
                    {
                        document.getElementById('wr_content').value = document.getElementById('save_comment_' + comment_id).value;
                        if (typeof char_count != 'undefined')
                            check_byte('wr_content', 'char_count');
                        if (document.getElementById('secret_comment_'+comment_id).value)
                            document.getElementById('wr_secret').checked = true;
                        else
                            document.getElementById('wr_secret').checked = false;
                    }
    
                    document.getElementById('comment_id').value = comment_id;
                    document.getElementById('w').value = work;
    
                    if(save_before)
                        $("#captcha_reload").trigger("click");
    
                    save_before = el_id;
                }
            }
    
            function comment_delete(href) {
                if (confirm("您要删除此评论吗?")) {
                    token = generate_token();
                    location.href = href + "?token=" + token + "&{{ request.query_params }}";
                    return true;
                }
                return false;
            }
    
            comment_box('', 'c'); // 添加注释以处理要可见的表单 (root亲爱的)
            comment_box('', 'c'); // 添加注释以处理要可见的表单 (root亲爱的)
    
            </script>
            <!-- } 评论写作结束 -->
        {% endif %}
        <script>
        jQuery(function($) {            
            //打开评论
            $("#cmt_btn").click(function(e){
                e.preventDefault();
                $(this).toggleClass("cmt_btn_op");
                $("#bo_vc").toggle();
            });
        });
        </script>
          </div>
          <div class="swiper-slide"></div>
        </div>
      </div>
  
    <!-- } 阅读结束公告板 -->

    <script>
        function board_move(href, sw) {
            var f = document.fwrite_copy;
            var sub_win = window.open(href, "move", "left=50, top=50, width=500, height=550, scrollbars=1");

            f.sw.value = sw;
            f.target = "move";
            f.submit();
        }
    </script>

    <script>
    $(function() {
        // 图像调整大小
        $("#bo_v_atc").viewimageresize();

        $("a.view_image").click(function() {
            window.open(this.href, "large_image", "location=yes,links=no,toolbar=no,top=10,left=10,width=10,height=10,resizable=yes,scrollbars=no,status=no");
            return false;
        });

        // 待定, 非推荐
        $("#good_button, #nogood_button").click(function() {
            {% if not login_member: %}
                alert("登录后，请使用.");
                return false;
            {% endif %}

            $("#bo_v_act_good").stop().fadeOut()
            $("#bo_v_act_nogood").stop().fadeOut()

            $("#good_button").removeClass("active");
            $("#nogood_button").removeClass("active");

            var $tx;
            if (this.id == "good_button") {
                $tx = $("#bo_v_act_good");
            } else {
                $tx = $("#bo_v_act_nogood");
            }

            excute_good(this.href, $(this), $tx);
            return false;
        });
    });

    var isRun = true;
    function excute_good(href, $el, $tx) {
        token = generate_token();

        if (token) {
            $.ajax({
                type: "POST",
                url: href,
                data: {"token": token},
                dataType: "json",
                beforeSend: function() {
                    if (isRun == false) {
                        alert("这是一个不正常的要求. 请稍等。.")
                        return false;
                    }
                    isRun = false;
                },
                success: function(data) {
                    if (data.status == "success") {
                        $el.addClass("active");
                    }
                    $("#good_button").find("strong").text(number_format(data.good));
                    $("#nogood_button").find("strong").text(number_format(data.nogood));
                    $tx.text(data.message);
                    $tx.fadeIn(200).delay(2500).fadeOut(200);
                },
                error: function(xhr, status, error) {
                    // 消息输出
                    var message = xhr.responseJSON ? xhr.responseJSON.message : xhr.responseText;
                    alert(xhr.status + " 错误 - " + message);
                },
                complete: function() {
                    isRun = true;
                }
            });
        } else {
            alert("创建令牌失败.");
        }
    }
    </script>
    <script>
      window.addEventListener('pageshow', function(event) {
      document.getElementById('loading').style.display = 'none';
    });
    var swiper = new Swiper('.post-swiper', {
        simulateTouch: true,
        initialSlide: 1, // "当前页面内容" 将幻灯片设置为初始幻灯片
        threshold: 60, // 必须识别Sif的最小距离 60px设置为
        on: {
            slideChange: function() {
            let activeIndex = this.activeIndex;
            let prevUrl = ""
            let nextUrl = ""

            // 上一页 URL
            {% if prev %}
                prevUrl = "{{ url_for('read_post', bo_table=board.bo_table, wr_id=prev.wr_id) }}"
            {% endif %}

            // 下一页 URL
            {% if next %}
                nextUrl = "{{ url_for('read_post', bo_table=board.bo_table, wr_id=next.wr_id) }}"
            {% endif %}

            if (activeIndex === 0) {
                if (prevUrl) {
                    // 显示加载图像并转到上一页
                    document.getElementById('loading').style.display = 'block';
                    window.location.href = prevUrl;
                } else {
                    // 在没有先前书写的情况下显示警告
                    alert("上一篇文章不存在.");    
                }
            } else if (activeIndex === 2) {
                if (nextUrl) {
                    // 显示加载图像并转到下一页
                    document.getElementById('loading').style.display = 'block';
                    window.location.href = nextUrl;
                } else {
                    // 没有下一文本时的警告
                    alert("以下帖子不存在.");
                }
            }
            this.slideTo(1, 0); // 2回到第二张幻灯片
          }
        }
      });
    </script>
    <!-- } 帖子阅读结束 -->
<form name="fwrite_copy" id="fwrite_copy" action="{{ url_for('move_post', bo_table=board.bo_table) }}" method="post">
    <input type="hidden" name="sw" value="">
    <input type="hidden" name="chk_wr_id[]" value="{{ write.wr_id }}">
</form>
{% if write_list %}
    {{ write_list|safe }}
{% endif %}
{% endblock content %}